function [ gimg, gftKernel ] = my_gauss2DFFT( img, w, sigma )
%MY_GAUSS2DFFT Summary of this function goes here


sY = size(img,1);
sX = size(img,2);

%create filter Kernel
middle = double(w)/2.0; 
[X, Y] = meshgrid(1:w);
gaussKernel = ( 1/ (2*pi*sigma^2))*exp(-((X-middle).^2+(Y-middle).^2)/(2*sigma^2) );

%building up empty image-sized version of kernel
greaterKernel = zeros(sY,sX);
%fill the kernel with entries:
greaterKernel(1:w,1:w) = gaussKernel;


%apply fourier transformation on the image and the greater kernel version
fftImg = fft2(img);
fftKernel = fft2(greaterKernel);


%applying the filter to the image (= multiplication in fft is equivalent
%   to summation in time domain)
for i=1:3,
    fftImg(:,:,i) = fftImg(:,:,i).*fftKernel;
end
%return the fft version of the filter kernel
%   and the image in time domain

gftKernel = fft2(gaussKernel);
gimg = ifft2(fftImg);

end

